package test.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import test.BaseObject;

public class FieldDemo extends BaseObject{
	
	static final String TAG = "FieldDemo";
	
	public static  void demo(String className) throws Exception{
		Class<?> class1 = null;  
        class1 = Class.forName(className);  
          
        //取得父类名称  
        Class<?>  superClass = class1.getSuperclass();  
        mLog.i(TAG, className + "类的父类名: " + superClass.getName());  
          
        mLog.i(TAG, "===============================================");  
          
        StringBuilder sb = new StringBuilder();  
        Field[] fields = class1.getDeclaredFields();  
        for (int i = 0; i < fields.length; i++) {  
        	sb.delete(0, sb.length());
        	sb.append("类中的第" + i  + "个成员" + fields[i]);
//        	sb.append("\t getDeclaringClass==" + fields[i].getDeclaringClass());
//        	sb.append("\t getDeclaredAnnotations==" + fields[i].getDeclaredAnnotations());
        	sb.append("\t getGenericType==" + fields[i].getGenericType());
        	sb.append("\t getModifiers==" + fields[i].getModifiers());
        	sb.append("\t getName==" + fields[i].getName());
        	sb.append("\t getType==" + fields[i].getType());
//        	sb.append("\t isSynthetic==" + fields[i].isSynthetic());
//        	sb.append("\t toGenericString==" + fields[i].toGenericString());
        	if (fields[i].getType().getPackage() != null){
        		sb.append("\t packageName==" + fields[i].getType().getPackage().getName());
        		if (fields[i].getType().getPackage().getName().equals("test.reflect")){
        			demo(fields[i].getType().getName());
        		}
        	}
        	
            mLog.i(TAG, sb.toString());  
        }  
        mLog.i(TAG, "----------------------------------------------------------------------------------------------------");  
        
        //我们判断两个条件，  getType==class test.reflect.WeaponBean
        for (int i=0; i<fields.length; i++){
        	if (fields[i].getType() == Class.class){
        		mLog.i(TAG, fields[i].getName());
        	}
        	
        	fields[i].getType().getPackage();
        	
        	
        	StringBuilder tempSb = new StringBuilder();
//        	tempSb.append(fields[i].)
        	
//        	Field[] fieldChild = fields[i].getType().getFields();
//        	
//        	for (int j=0; j<fieldChild.length; j++){
//        		mLog.i(TAG, "j=" + j + "  " + fieldChild[j]);
//        	}
//        	
//        	mLog.i(TAG, fields[i].getType().getFields().toString());
        }
          
          
//        //取得类方法  
//        Method[] methods = class1.getDeclaredMethods();  
//        for (int i = 0; i < methods.length; i++) {  
//        	mLog.i(TAG, "i = " + i);
//            mLog.i(TAG, "Demo6,取得SuperMan类的方法：");  
//            mLog.i(TAG, "函数名：" + methods[i].getName());  
//            mLog.i(TAG, "函数返回类型：" + methods[i].getReturnType());  
//            mLog.i(TAG, "函数访问修饰符：" + Modifier.toString(methods[i].getModifiers()));  
//            mLog.i(TAG, "函数代码写法： " + methods[i]);  
//        }  
//          
//        mLog.i(TAG, "############################");  
        
        //取得类实现的接口,因为接口类也属于Class,所以得到接口中的方法也是一样的方法得到哈  
//        Class<?> interfaces[] = class1.getInterfaces();  
//        for (int i = 0; i < interfaces.length; i++) {  
//        	mLog.i(TAG, "接口  i = " + i);
//            mLog.i(TAG, "实现的接口类名: " + interfaces[i].getName() );  
//        }  
          
	}
	
}
